import request from '@/utils/request'
import store from '../store/index.js'

export function getAllOrg() {
  return request({
    url: '/organization/server/all/',
    method: 'get'
  })
}

export function getOrgById(id) {
  return request({
    url: '/organization/server/id',
    method: 'get',
    params: {
      orgId: id
    }
  })
}

export function addOrg(org) {
  return request({
    url: '/organization/server/append',
    method: 'post',
    data: {
      // 'orgId': 49,
      orgName: org.orgName,
      orgType: org.orgType,
      orgImg: org.orgImg,
      head: org.head,
      depositBank: org.depositBank,
      account: org.account,
      contacts: org.contacts,
      contactNumber: org.contactNumber,
      shareRatio: org.shareRatio,
      referenceId: org.referenceId,
      referenceRatio: org.referenceRatio,
      orgAddress: org.orgAddress,
      contactTel: org.contactTel,
      orgEmail: org.orgEmail,
      orgTime: org.orgTime
    }
  })
}

export function updateOrg(org) {
  return request({
    url: '/organization/server/update',
    method: 'post',
    data: {
      orgId: org.orgId,
      orgName: org.orgName,
      orgType: org.orgType,
      orgImg: org.orgImg,
      head: org.head,
      depositBank: org.depositBank,
      account: org.account,
      contacts: org.contacts,
      contactNumber: org.contactNumber,
      shareRatio: org.shareRatio,
      referenceId: org.referenceId,
      referenceRatio: org.referenceRatio,
      orgAddress: org.orgAddress,
      contactTel: org.contactTel,
      orgEmail: org.orgEmail,
      orgTime: org.orgTime
    }
  })
}

export function getOrgByOrgHead() {
  return request({
    url: '/organization/server/head',
    method: 'get',
    params: {
      orgHead: store.getters.token
    }
  })
}

export function deleteById(id) {
  return request({
    url: '/organization/server/remove',
    method: 'post',
    data: {
      orgId: id
    }
  })
}

export function conditionSearch(search) {
  return request({
    url: '/organization/search1',
    method: 'get',
    params: {
      orgType: search.orgType,
      orgName: search.orgName
    }
  })
}

export function mohuSearch(str) {
  return request({
    url: '/organization/search2',
    method: 'get',
    params: {
      str: str
    }
  })
}
